package test;

import common.Utils;
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.time.Duration;

public class HomePage extends Utils {
    public static String url="http://127.0.0.1:9580/index.html";
    public HomePage() {
        super(url);
    }

    //切换夜间/白天模式
    public void SwitchNight() throws InterruptedException {
        LoginPage loginPage = new LoginPage();
        loginPage.login();
        driver.findElement(By.cssSelector("body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > a.nav-link.px-0.hide-theme-dark > svg")).click();
        driver.findElement(By.cssSelector("body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > a.nav-link.px-0.hide-theme-light > svg")).click();
    }

    //查看别人的帖子
    public void OtherPeople() throws InterruptedException {
        //查看帖子
        driver.findElement(By.cssSelector("#artical-items-body > div:nth-child(1) > div > div.col > div.text-truncate > a > strong")).click();
        //点赞
        driver.findElement(By.cssSelector("#details_btn_like_count")).click();

        //私信
        driver.findElement(By.cssSelector("#btn_details_send_message")).click();
        driver.findElement(By.cssSelector("#index_message_receive_content")).sendKeys("你好！");
        WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5));
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("#index_message_receive_content")));
        Thread.sleep(1000);
        driver.findElement(By.cssSelector("#btn_index_send_message")).click();

        //查看/回复私信
        driver.findElement(By.cssSelector("body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > div > a > svg")).click();
        driver.findElement(By.cssSelector("#index_div_message_list > div:nth-child(1) > div > div.col.text-truncate > a")).click();
        driver.findElement(By.cssSelector("#btn_index_message_reply")).click();
        Thread.sleep(2000);
        driver.findElement(By.cssSelector("#index_message_reply_receive_content")).sendKeys("你也好");
        driver.findElement(By.cssSelector("#btn_index_send_message_reply")).click();
        driver.findElement(By.cssSelector("#index_message_offcanvasEnd > div.offcanvas-header > button")).click();


        //退出/注销
        driver.findElement(By.cssSelector("#index_nav_avatar")).click();
        driver.findElement(By.cssSelector("#index_user_logout")).click();
        String title =  driver.getTitle();
        assert title.equals("比特论坛 - 用户登录");


    }



}
